package day08.homework;

import java.util.Scanner;

public class CodeBarDemo {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        System.out.println("请你输入条形码>");
        String bar = sc.nextLine();
        checkBar(bar);
    }

    private static void checkBar(String bar){
        int oo = 0;
        for(int i = 1;i < bar.length()-1;i+=2){
            oo+=bar.charAt(i)-'0';
        }
        oo*=3;
        int ji = 0;
        for (int i = 0; i<bar.length()-2;i+=2){
            ji+=Integer.valueOf(String.valueOf(bar.charAt(i)));
        }
        int result = oo + ji;
        char checkBarCode = bar.charAt(bar.length()-1);

        if(result % 10 == 0){
            if(checkBarCode == '0'){
                System.out.println("正品！校验码是：0");
            }else{
                System.out.println("假冒品！校验码是:0");
            }
        }else{
            int n = 10 -result % 10;
            if(String.valueOf(n).equals(String.valueOf(checkBarCode))){
                System.out.println("正品!校验码是:"+n);

            }else{
                System.out.println("假冒品！校验码是:"+n);
            }
        }
    }
}
